package chc

import (
	"fmt"
	"time"
)

type Config struct {
	Host     string
	AltHosts string

	User string
	Pass string

	Database string

	RTO int
	WTO int

	IsCluster bool

	DefaultTimeLoc *time.Location
}

func (config *Config) getConnectionParams() string {

	if 1 > config.RTO {
		config.RTO = 10
	}
	if 1 > config.WTO {
		config.WTO = 20
	}

	param := fmt.Sprintf("?read_timeout=%d&write_timeout=%d", config.RTO, config.WTO)
	if "" != chSession.Config.User {
		param += "&username=" + chSession.Config.User
	}
	if "" != chSession.Config.Pass {
		param += "&password=" + chSession.Config.Pass
	}
	if "" != chSession.Config.Database {
		param += "&database=" + chSession.Config.Database
	}

	return param
}

func (config *Config) getConnectionAltHostsParams() string {
	if "" == chSession.Config.AltHosts {
		return ""
	}

	return "&alt_hosts=" + chSession.Config.AltHosts
}
